package com.zyh.status;
import com.zyh.controller.UserController;
import com.zyh.utils.GetNumber;
import com.zyh.utils.JdbcUtils;
import com.zyh.utils.Menu;

public class UserLogin {
    UserController userController = new UserController();
    GetNumber getNumber = new GetNumber();
    JdbcUtils jdbcUtils = new JdbcUtils();
    NotLogin notLogin = new NotLogin();

    public void run() {
        try {
            while (true) {
                Menu.printMainMenu();
                int opt = getNumber.getUserInputAsInt();
                switch (opt) {
                    case 1:
                        userController.login();
                        break;
                    case 2:
                        userController.register();
                        break;
                    case 3:
                        notLogin.failed();
                        break;
                    case 0:
                        System.out.println("谢谢使用，再见！");
                        jdbcUtils.closeAllConnections();
                        return;
                    default:
                        System.out.println("无效选项，请重新选择");
                }
            }
        } finally {
            jdbcUtils.closeAllConnections();
        }
    }
}
